
*************************Figure 1*******************
use "C:\Users\Frank\Documents\My Dropbox\Research\Papers\Women and Electoral Reform\Replication Data.dta", clear
gen axis=_n+0 in 1/57
replace axis=axis+1955
gen mean=.
gen ll=.
gen ul=.
replace pctwomenlegb=pctwomenlegb*100
forvalues y=1956(1)2012{
summ pctwomenlegb if year==`y'
replace mean=r(mean) if axis==`y'
replace ll=r(mean)-(.5*r(sd)) if axis==`y'
replace ul=r(mean)+(.5*r(sd)) if axis==`y'
}
*
twoway (rspike ll ul axis) (scatter mean axis, mcolor(black) scheme(s2mono)  ///
ytitle("Pct. Women in the Legislature") xtitle("Year") legend(order(2 "World Average" ///
1 "Std. Deviation")) ///
)

*************************variable table*******************
use "C:\Users\Frank\Documents\My Dropbox\Research\Papers\Women and Electoral Reform\Replication Data.dta", clear

replace pctwomenlegb=pctwomenlegb*100
gen axis=_n+0 in 1/10
gen mean=.
gen sd=.
local a=1
foreach x in pctwomenlegb jointflfpart yrssincesuffrage nquotaparties seats ///
 tier1_avemag rank median nquota4 maj_seat_reform {
 summ `x'
 replace mean=r(mean) if axis==`a'
 replace sd=r(sd) if axis==`a'
 local a=`a'+1
 }
*
label define axis 1 "Pct. Women" 2 "Female Labor Force Participation" 3 "Years Since Suffrage" ///
4 "N of Quota Parties" 5 "Seats" 6 "District Magnitude" 7 "Personal Vote Rank" ///
8 "Democracy" 9 "National Quota" ///
10 "Majoritarian Reform" 
label values axis axis
format %9.3f mean
format %9.3f sd
keep axis mean sd
drop if axis==.


**************model 1************
use "C:\Users\Frank\Documents\My Dropbox\Research\Papers\Women and Electoral Reform\Replication Data.dta", clear
xtpcse d.pctwomenlegb l.(pctwomenlegb) l.(yrssincesuffrage jointflfpart median ///
nquota4 nquotaparties legislative_type1) ///
d.(yrssincesuffrage jointflfpart median nquota4 nquotaparties ) d_legislative_type1 ///
, p c(ar1)

gen axis=_n+0 in 1/18

label define axis 1 "Pct. Women t-1" 2 "Yrs. since Suffrage t-1"  3 "Female Labor Force t-1" ///
4 "Democracy t-1" 5 "National Quota t-1" 6 "N. Quota Parties t-1" ///
7 "Elec. System t-1" 8 "D Yrs since Suff." 9 "D Female Labor Force" ///
10 "D Democracy" 11 "D National Quota" 12 "D N. Quota Parties" ///
13 "D Elec. System" 14 "Intercept" 15 "N of Countries" 16 "N of Cases" ///
17 "r2" 18 "Chi Square"

label values axis axis

matrix b=e(b)
*get coeff for rho, absolute value
local r=b[1,1]
local r=abs(`r')
di `r'
matrix b1=b[1, 1..7]
matrix r_coeff=b1/`r'
matrix r_coeff=r_coeff'
svmat double r_coeff, name(r_coeff)

*raw coeff
matrix coeff= b[1,1..14]
matrix coeff=coeff'
svmat double coeff, name(coeff)

*matrix of covariance
matrix v=e(V)
matrix list v
matrix v1=v[1,1..7]
matrix covar=v1'
svmat double covar, name(covariance)

*matrix of variance
forvalues x=1(1)14{
scalar b`x'=v[`x', `x']
}
matrix var = (b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14)
matrix var=var'
svmat double var, name(variance)


*gen se
summ coeff1 if axis==1, meanonly
local b=r(mean)
qui summ variance1 if axis==1, meanonly
local v_b=r(mean)

gen sigma_sq_ratio=((1/(`b'*`b'))*variance1) + ((coeff1*coeff1)/(`b'*`b'*`b'*`b'))*(`v_b') ///
-2*((coeff1/(`b'*`b'*`b'))*(covariance1)) if axis<8


gen standard_error=sqrt(sigma_sq_ratio) if axis<8
replace standard_error=sqrt(variance1) if axis>7
replace standard_error=sqrt(variance1) if axis==1
gen z_score=r_coeff1/standard_error if axis<8
replace z_score=coeff1/standard_error if axis>7

gen p_value=2*(1-normal(abs(z_score)))
gen coefficient=r_coeff1 if axis>1 & axis<8
replace coefficient=coeff1 if axis==1
replace coefficient=coeff1 if axis>7
replace coefficient=e(N_g) if axis==15
replace coefficient=e(N) if axis==16
replace coefficient=e(r2) if axis==17
replace coefficient=e(chi2) if axis==18
replace p_value=e(p) if axis==18
order coefficient, before(standard_error)
order axis, before(coefficient)
format %9.3f p_value
format %9.3f coefficient
format %9.3f standard_error
format %9.3f z_score

keep axis coefficient standard_error z_score p_value
rename coefficient coefficient_m1
rename standard_error standard_error_m1
rename z_score z_score_m1
rename p_value p_value_m1
drop if axis==.
tempfile m1
save `m1', replace

***************Model 2..district magnitude*************************
use "C:\Users\Frank\Documents\My Dropbox\Research\Papers\Women and Electoral Reform\Replication Data.dta", clear

xtpcse d.pctwomenlegb l.(pctwomenlegb) l.(yrssincesuffrage jointflfpart median ///
nquota4 nquotaparties ln_tier1_avemag) ///
d.(yrssincesuffrage jointflfpart median nquota4 nquotaparties ln_tier1_avemag) ///
, p c(ar1)
gen axis=_n+0 in 1/18

label define axis 1 "Pct. Women t-1" 2 "Yrs. since Suffrage t-1"  3 "Female Labor Force t-1" ///
4 "Democracy t-1" 5 "National Quota t-1" 6 "N. Quota Parties t-1" ///
7 "Elec. System t-1" 8 "D Yrs since Suff." 9 "D Female Labor Force" ///
10 "D Democracy" 11 "D National Quota" 12 "D N. Quota Parties" ///
13 "D Elec. System" 14 "Intercept" 15 "N of Countries" 16 "N of Cases" ///
17 "r2" 18 "Chi Square"

label values axis axis

matrix b=e(b)
*get coeff for rho, absolute value
local r=b[1,1]
local r=abs(`r')
di `r'
matrix b1=b[1, 1..7]
matrix r_coeff=b1/`r'
matrix r_coeff=r_coeff'
svmat double r_coeff, name(r_coeff)

*raw coeff
matrix coeff= b[1,1..14]
matrix coeff=coeff'
svmat double coeff, name(coeff)

*matrix of covariance
matrix v=e(V)
matrix list v
matrix v1=v[1,1..7]
matrix covar=v1'
svmat double covar, name(covariance)

*matrix of variance
forvalues x=1(1)14{
scalar b`x'=v[`x', `x']
}
matrix var = (b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14)
matrix var=var'
svmat double var, name(variance)

rename r_coeff1 r_coeff2
rename coeff1 coeff2
rename variance1 variance2
rename covariance1 covariance2
*gen se
summ coeff2 if axis==1, meanonly
local b=r(mean)
qui summ variance2 if axis==1, meanonly
local v_b=r(mean)

gen sigma_sq_ratio=((1/(`b'*`b'))*variance2) + ((coeff2*coeff2)/(`b'*`b'*`b'*`b'))*(`v_b') ///
-2*((coeff2/(`b'*`b'*`b'))*(covariance2)) if axis<8


gen standard_error=sqrt(sigma_sq_ratio) if axis<8
replace standard_error=sqrt(variance2) if axis>7
replace standard_error=sqrt(variance2) if axis==1
gen z_score=r_coeff2/standard_error if axis<8
replace z_score=coeff2/standard_error if axis>7

gen p_value=2*(1-normal(abs(z_score)))
gen coefficient=r_coeff2 if axis>1 & axis<8
replace coefficient=coeff2 if axis==1
replace coefficient=coeff2 if axis>7
replace coefficient=e(N_g) if axis==15
replace coefficient=e(N) if axis==16
replace coefficient=e(r2) if axis==17
replace coefficient=e(chi2) if axis==18
replace p_value=e(p) if axis==18
order coefficient, before(standard_error)
order axis, before(coefficient)
format %9.3f p_value
format %9.3f coefficient
format %9.3f standard_error
format %9.3f z_score

keep axis coefficient standard_error z_score p_value
rename coefficient coefficient_m2
rename standard_error standard_error_m2
rename z_score z_score_m2
rename p_value p_value_m2
drop if axis==.
tempfile m2
save `m2', replace


***************Model 3..pers_rank*************************
use "C:\Users\Frank\Documents\My Dropbox\Research\Papers\Women and Electoral Reform\Replication Data.dta", clear

xtpcse d.pctwomenlegb l.(pctwomenlegb) l.(yrssincesuffrage jointflfpart median ///
nquota4 nquotaparties ln_pers_rank) ///
d.(yrssincesuffrage jointflfpart median nquota4 nquotaparties ln_pers_rank) , p c(ar1)

gen axis=_n+0 in 1/18

label define axis 1 "Pct. Women t-1" 2 "Yrs. since Suffrage t-1"  3 "Female Labor Force t-1" ///
4 "Democracy t-1" 5 "National Quota t-1" 6 "N. Quota Parties t-1" ///
7 "Elec. System t-1" 8 "D Yrs since Suff." 9 "D Female Labor Force" ///
10 "D Democracy" 11 "D National Quota" 12 "D N. Quota Parties" ///
13 "D Elec. System" 14 "Intercept" 15 "N of Countries" 16 "N of Cases" ///
17 "r2" 18 "Chi Square"

label values axis axis

matrix b=e(b)
*get coeff for rho, absolute value
local r=b[1,1]
local r=abs(`r')
di `r'
matrix b1=b[1, 1..7]
matrix r_coeff=b1/`r'
matrix r_coeff=r_coeff'
svmat double r_coeff, name(r_coeff)

*raw coeff
matrix coeff= b[1,1..14]
matrix coeff=coeff'
svmat double coeff, name(coeff)

*matrix of covariance
matrix v=e(V)
matrix list v
matrix v1=v[1,1..7]
matrix covar=v1'
svmat double covar, name(covariance)

*matrix of variance
forvalues x=1(1)14{
scalar b`x'=v[`x', `x']
}
matrix var = (b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14)
matrix var=var'
svmat double var, name(variance)

rename r_coeff1 r_coeff3
rename coeff1 coeff3
rename variance1 variance3
rename covariance1 covariance3

*gen se
summ coeff3 if axis==1, meanonly
local b=r(mean)
qui summ variance3 if axis==1, meanonly
local v_b=r(mean)

gen sigma_sq_ratio=((1/(`b'*`b'))*variance3) + ((coeff3*coeff3)/(`b'*`b'*`b'*`b'))*(`v_b') ///
-2*((coeff3/(`b'*`b'*`b'))*(covariance3)) if axis<8


gen standard_error=sqrt(sigma_sq_ratio) if axis<8
replace standard_error=sqrt(variance3) if axis>7
replace standard_error=sqrt(variance3) if axis==1
gen z_score=r_coeff3/standard_error if axis<8
replace z_score=coeff3/standard_error if axis>7

gen p_value=2*(1-normal(abs(z_score)))
gen coefficient=r_coeff3 if axis>1 & axis<8
replace coefficient=coeff3 if axis==1
replace coefficient=coeff3 if axis>7
replace coefficient=e(N_g) if axis==15
replace coefficient=e(N) if axis==16
replace coefficient=e(r2) if axis==17
replace coefficient=e(chi2) if axis==18
replace p_value=e(p) if axis==18
order coefficient, before(standard_error)
order axis, before(coefficient)
format %9.3f p_value
format %9.3f coefficient
format %9.3f standard_error
format %9.3f z_score

keep axis coefficient standard_error z_score p_value
rename coefficient coefficient_m3
rename standard_error standard_error_m3
rename z_score z_score_m3
rename p_value p_value_m3
drop if axis==.
tempfile m3
save `m3', replace

**********************************model 4 seats*********************************
use "C:\Users\Frank\Documents\My Dropbox\Research\Papers\Women and Electoral Reform\Replication Data.dta", clear

xtpcse d.pctwomenlegb l.(pctwomenlegb) l.(yrssincesuffrage jointflfpart median  ///
nquota4 nquotaparties ln_seats) d.(yrssincesuffrage jointflfpart median  ///
nquota4 nquotaparties ln_seats) ///
, p c(ar1)
gen axis=_n+0 in 1/18

label define axis 1 "Pct. Women t-1" 2 "Yrs. since Suffrage t-1"  3 "Female Labor Force t-1" ///
4 "Democracy t-1" 5 "National Quota t-1" 6 "N. Quota Parties t-1" ///
7 "Elec. System t-1" 8 "D Yrs since Suff." 9 "D Female Labor Force" ///
10 "D Democracy" 11 "D National Quota" 12 "D N. Quota Parties" ///
13 "D Elec. System" 14 "Intercept" 15 "N of Countries" 16 "N of Cases" ///
17 "r2" 18 "Chi Square"

label values axis axis

matrix b=e(b)
*get coeff for rho, absolute value
local r=b[1,1]
local r=abs(`r')
di `r'
matrix b1=b[1, 1..7]
matrix r_coeff=b1/`r'
matrix r_coeff=r_coeff'
svmat double r_coeff, name(r_coeff)

*raw coeff
matrix coeff= b[1,1..14]
matrix coeff=coeff'
svmat double coeff, name(coeff)

*matrix of covariance
matrix v=e(V)
matrix list v
matrix v1=v[1,1..7]
matrix covar=v1'
svmat double covar, name(covariance)

*matrix of variance
forvalues x=1(1)14{
scalar b`x'=v[`x', `x']
}
matrix var = (b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14)
matrix var=var'
svmat double var, name(variance)

rename r_coeff1 r_coeff4
rename coeff1 coeff4
rename variance1 variance4
rename covariance1 covariance4

*gen se
summ coeff4 if axis==1, meanonly
local b=r(mean)
qui summ variance4 if axis==1, meanonly
local v_b=r(mean)

gen sigma_sq_ratio=((1/(`b'*`b'))*variance4) + ((coeff4*coeff4)/(`b'*`b'*`b'*`b'))*(`v_b') ///
-2*((coeff4/(`b'*`b'*`b'))*(covariance4)) if axis<8


gen standard_error=sqrt(sigma_sq_ratio) if axis<8
replace standard_error=sqrt(variance4) if axis>7
replace standard_error=sqrt(variance4) if axis==1
gen z_score=r_coeff4/standard_error if axis<8
replace z_score=coeff4/standard_error if axis>7

gen p_value=2*(1-normal(abs(z_score)))
gen coefficient=r_coeff4 if axis>1 & axis<8
replace coefficient=coeff4 if axis==1
replace coefficient=coeff4 if axis>7
replace coefficient=e(N_g) if axis==15
replace coefficient=e(N) if axis==16
replace coefficient=e(r2) if axis==17
replace coefficient=e(chi2) if axis==18
replace p_value=e(p) if axis==18
order coefficient, before(standard_error)
order axis, before(coefficient)
format %9.3f p_value
format %9.3f coefficient
format %9.3f standard_error
format %9.3f z_score

keep axis coefficient standard_error z_score p_value
rename coefficient coefficient_m4
rename standard_error standard_error_m4
rename z_score z_score_m4
rename p_value p_value_m4
drop if axis==.
tempfile m4
save `m4', replace




use `m1', clear

mmerge axis using `m2'
mmerge axis using `m3'
mmerge axis using `m4'
